package com.yuyu.tt.service;

import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuyu.tt.context.TenantContextHolder;
import com.yuyu.tt.domain.SysUser;
import com.yuyu.tt.mapper.SysUserMapper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * @description 针对表【sys_user】的数据库操作Service实现
 * @createDate 2024-11-20 11:16:32
 */
@Service
public class SysUserService extends ServiceImpl<SysUserMapper, SysUser> {


    @Async("simpleAsyncExec")
    public void saveUserByAsyncAnnotation() {
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        save(SysUser.builder()
                .username(RandomUtil.randomString(8))
                .password(RandomUtil.randomString(8))
                .build());
        TenantContextHolder.removeProjectCode();
    }

    public void saveUserByTaskExec() {
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        save(SysUser.builder()
                .username(RandomUtil.randomString(8))
                .password(RandomUtil.randomString(8))
                .build());
    }

    @Async("taskExecutor")
    public void saveUserByAsyncAnnotation2() {
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        save(SysUser.builder()
                .username(RandomUtil.randomString(8))
                .password(RandomUtil.randomString(8))
                .build());
    }
}




